package com.dq.mybatis.demo;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;


public class AppTest3 {

	private SqlSessionFactory factory;

	{
		try (InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml")){
			//读取配置文件后，获取链接数据库的信息，创建好连接池。创建SqlSessionFactory工厂，使用工厂创建factory对象。
			factory = new SqlSessionFactoryBuilder().build(inputStream);
		} catch (IOException e){
			e.printStackTrace();
		}
	}
	
	@Test
	public void find3() {
		SqlSession session = factory.openSession();
		List<Emp> list = session.selectList("mapper.Emp.find3");
		for(Emp p : list) {
			System.out.println(p);
		}
		session.close();
	}
	
	@Test
	public void find4() {
		SqlSession session = factory.openSession();
		List<Emp> list = session.selectList("mapper.Emp.find4");
		for(Emp p : list) {
			System.out.println(p);
		}
		session.close();
	}
	
	@Test
	public void find5() {
		SqlSession session = factory.openSession();
		List<Emp> list = session.selectList("mapper.Emp.find5");
		for(Emp p : list) {
			System.out.println(p);
		}
		session.close();
	}

}
